// 鼠标移动左侧边栏
export function useWindowEvent(containerLeftRef, containerRightRef) {

    // 鼠标移动
    const onmousemoveLeft = (e) => {
        let { clientX: moveX } = e || window.event
        if (moveX < 200) {
            moveX = 200
        }
        containerLeftRef.value.style.width = moveX + 'px'
    }

    const onmousemoveRight = (e) => {
        let { clientX: moveX } = e || window.event
        let dur = window.innerWidth - moveX
        if (dur < 200) {
            dur = 200
        }
        containerRightRef.value.style.width = dur + 'px'
    }

    // 左边边线鼠标抬起
    const onmouseupLeft = () => {
        document.removeEventListener('mousemove', onmousemoveLeft)
        document.removeEventListener('mouseup', onmouseupLeft)
    }

    // 左边边线鼠标按下事件
    const onDividerLeftDown = () => {
        document.addEventListener('mousemove', onmousemoveLeft)
        document.addEventListener('mouseup', onmouseupLeft)
    }

    // 右边边线鼠标抬起
    const onmouseupRight = () => {
        document.removeEventListener('mousemove', onmousemoveRight)
        document.removeEventListener('mouseup', onmouseupRight)
    }

    // 右边边线鼠标按下事件
    const onDividerRightDown = () => {
        document.addEventListener('mousemove', onmousemoveRight)
        document.addEventListener('mouseup', onmouseupRight)
    }

    return {
        onDividerLeftDown,
        onDividerRightDown
    };
}